package shanhu;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.alibaba.excel.EasyExcel;
import test.excel.ExcelListener;
import test.excel.ExcelListenerV2;
import test.excel.HospitalEntity;

import java.io.FileInputStream;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author DengZhiYuan
 * @version 1.0
 * @date 2023/3/13 19:00
 */
public class WptApiData {

    public static void main(String[] args) throws Exception {

        new WptApiData().repairData();
    }


    /**
     * 修复2022-12-27 到 2023-03-13日的数据
     * @author DengZhiYuan
     * @version 1.0
     * @date 2023/3/13 18:41
     * @param
     * @return
     */
    public void repairData() throws Exception {

        String readFile = "C:\\Users\\dzy\\Desktop\\20230313TPA\\副本远盟221227-230313修复3.xlsx";
        String saveFile = "C:\\Users\\dzy\\Desktop\\20230313TPA\\rejson.txt";

        Map<String,String> typeMap = new HashMap<>();
        typeMap.put("24小时电话医生","15101015001");
        typeMap.put("全程无缝隙紧急救援","13101015001");
        typeMap.put("重大疾病绿色通道","12101015003");
        typeMap.put("重大疾病绿色通道升级服务","12101015002");

        Map<String,String> idCardTypeMap = new HashMap<>();
        idCardTypeMap.put("身份证","0");
        idCardTypeMap.put("户口簿","5");
        idCardTypeMap.put("军官证","2");

        ExcelListenerV2 excelListener = new ExcelListenerV2();
        EasyExcel.read(readFile, RecordTpaDTO.class,excelListener).sheet().doRead();
        List<RecordTpaDTO> list = excelListener.getList();


        for (RecordTpaDTO item: list) {
            if(StrUtil.isBlank(item.getCardType())){
                item.setCardType("身份证");
            }

            item.setServiceNo(typeMap.get(item.getServiceNo()));
            item.setDepartmentId(101015L);
            item.setCardType(idCardTypeMap.get(item.getCardType()));
            item.setPushBatch(1);
            item.setPushCount(1);
            item.setPushTotalBatch(1);
            item.setPushTotalCount(1);
            item.setInterestStatus(2L);
            item.setBatchId(1L);
            item.setStartTime(DateUtil.format(DateUtil.parse(item.getStartTime(), DatePattern.CHINESE_DATE_PATTERN), DatePattern.NORM_DATE_PATTERN) );
            item.setEndTime(DateUtil.format(DateUtil.parse(item.getEndTime(), DatePattern.CHINESE_DATE_PATTERN), DatePattern.NORM_DATE_PATTERN) );
        }
        FileUtil.writeLines(list,saveFile , Charset.defaultCharset() );

//        ExcelReader excelReader = ExcelUtil.getReader(new FileInputStream(readFile), 0);
//        List<RecordTpaDTO> recordTpaDTOS = excelReader.readAll(RecordTpaDTO.class);
//        System.out.println(recordTpaDTOS.get(0).toString());




    }




}
